var TableLogManagerLogins = function () {
    return {
        init: function () {
			//初始化日期
			$('#dashboard-report-range').daterangepicker({
                opens: (App.isRTL() ? 'right' : 'left'),
                startDate: moment().subtract('days', 29),
                endDate: moment(),
                //minDate: '2012/01/01/',
                maxDate: moment(), //最大时间
                dateLimit: {
                    days: 60
                },
                showDropdowns: false,
                showWeekNumbers: true,
                timePicker: false,
                timePickerIncrement: 1,
                timePicker12Hour: true,
                ranges: {
                    '今天': [moment(), moment()],
                    '昨天': [moment().subtract('days', 1), moment().subtract('days', 1)],
                    '最近7天': [moment().subtract('days', 6), moment()],
                    '最近30天': [moment().subtract('days', 29), moment()],
                    '本月': [moment().startOf('month'), moment().endOf('month')],
                    '上月': [moment().subtract('month', 1).startOf('month'), moment().subtract('month', 1).endOf('month')]
                },
                buttonClasses: ['btn'],
                applyClass: 'blue',
                cancelClass: 'default',
                format: 'YYYY/MM/DD',
                separator: ' to ',
                locale: {
                    applyLabel : '确定',
				   cancelLabel : '取消',
				   fromLabel : '起始时间',
				   toLabel : '结束时间',
				   customRangeLabel : '自定义',
                    daysOfWeek: ['日', '一', '二', '三', '四', '五', '六'],
                    monthNames: ['一月', '二月', '三月', '四月', '五月', '六月', '七月', '八月', '九月', '十月', '十一月', '十二月'],
                    firstDay: 1
                }
            },
            function (start, end) {
                console.log("Callback has been called!");
                $('#dashboard-report-range span').html(start.format('YYYY/MM/DD') + ' - ' + end.format('YYYY/MM/DD'));
            }
            );


            $('#dashboard-report-range span').html(moment().subtract('days', 29).format('YYYY/MM/DD') + ' - ' + moment().format('YYYY/MM/DD'));
            $('#dashboard-report-range').show();
			
            var oTable = $('#table_manager').dataTable({
                "aLengthMenu": [
                    [-1,5, 15, 20],
                    ["全部",'5条', '15条', '20条'] 
                ],
                "iDisplayLength": 20,
				"serverSide":true,
				//"aaSorting":[[0,'desc']],
                "sPaginationType": "bootstrap",
				//"bStateSave": true, 
                "oLanguage": {
					"sSearch":"搜索",
                    "sLengthMenu": "每页显示 _MENU_ 记录",    
					"sEmptyTable":"没有数据",
					"sInfo": "当前数据为从第 _START_ 到第 _END_ 条数据；总共有 _TOTAL_ 条记录",   
					"sInfoEmpty": "没有数据",   
					"sInfoFiltered" : "",
					"sInfoPostFix" : "",
					"sLoadingRecords":"",
					"sProcessing": "正在加载数据...", 
					"sZeroRecords": "没有检索到数据", 
                    "oPaginate": {   
						"sFirst": "首页",   
						"sPrevious": "上一页",   
						"sNext": "下一页",   
						"sLast": "尾页"  
					}   
                },
				"sAjaxSource":ajaxUrl,
				"sAjaxDataProp": "data",
				"fnServerParams": function ( aoData ) {
					aoData.push( { "name": 'dr',"value":function(){
							return $("#dashboard-report-range span").html();
						}
					});
				},
				"aoColumns": [
					{"sTitle":'序号',"mDataProp": 'loginId'},
					{"sTitle":'用户名',"mDataProp": 'loginName'},
					{"sTitle":'姓名',"mDataProp": 'managerName'},
					{"sTitle":'登录时间',"mDataProp": 'loginTime'},
					{"sTitle":'登录IP',"mDataProp": 'loginIp'}
				],
                "aoColumnDefs": [{
                        'bSortable': false,
						'aTargets': [0,1,2,4]
                    }
                ],
				"fnCreatedRow":function(nRow,aData,iDataIndex){
					$('td:eq(0)',nRow).html(iDataIndex+1);//为第一个单元格增加序号
				}
            });

            jQuery('#table_manager_wrapper .dataTables_filter input').addClass("form-control input-medium input-inline"); // modify table search input
            jQuery('#table_manager_wrapper .dataTables_length select').addClass("form-control input-small"); // modify table per page dropdown
            jQuery('#table_manager_wrapper .dataTables_length select').select2({
                showSearchInput : false 
            }); 
			
			$("#dashboard-report-range").on('apply.daterangepicker',function(){
				
				oTable.fnReloadAjax();
			});
			
        }

    };

}();